<?php

class Article_model extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    private $tbl = "article";
    function get_all() {
        $this->db->select();
        $this->db->from($this->tbl." as ar");
        $this->db->join("article_of_center as aoc", "ar.id_article = aoc.id_article",'left');
        $this->db->join("center as ct", "aoc.id_center = ct.id_center",'left');
        $this->db->join('type_center as tc', 'ct.id_type_center = ct.id_type_center','left');
        
        return  $this->db->get();
    }
    function get_by_type($id_type_center) {
        $this->db->select();
        $this->db->from($this->tbl." as ar");
        $this->db->join("article_of_center as aoc", "ar.id_article = aoc.id_article",'left');
        $this->db->join("center as ct", "aoc.id_center = ct.id_center",'left');
        $this->db->join('type_center as tc', 'tc.id_type_center = ct.id_type_center');
        $this->db->where("tc.id_type_center",$id_type_center);
        
        return  $this->db->get();
    }
    function get_by_id($id) {
        $this->db->select();
        $this->db->from($this->tbl." as ar");
        $this->db->join("article_of_center as aoc", "ar.id_article = aoc.id_article",'left');
        $this->db->join("center as ct", "aoc.id_center = ct.id_center",'left');
        $this->db->join('type_center as tc', 'ct.id_type_center = ct.id_type_center','left');
        
        $this->db->where('ar.id_article',$id);
        $this->db->limit(1);
        
        return  $this->db->get();
    }
}

